﻿using System;
using System.Collections.Generic;
using System.Text;
using Graffiti.Core;
using GraffitiExtras.Extensions.InstalledThemes;

namespace GraffitiExtras.Widgets.ThemeExplorer
{
    /// <summary>
    /// A widget which displays a list of currently installed themes
    /// </summary>
    [WidgetInfo("a7abe913-0de7-45a5-9cc5-6c6c5809e800",
        "Theme Explorer",
        "Represents a list of currently installed themes")]
    public class ThemeExplorer : Widget
    {
        /// <summary>
        /// Override name to give a more meaningful
        /// value when displayed in a list.
        /// </summary>

        public override string Name
        {
            get
            {
                if (string.IsNullOrEmpty(Title))
                    return "Theme Explorer";
                else
                    return Title + " (Theme Explorer Widget)";
            }
        }

        public override string RenderData()
        {
            StringBuilder sb = new StringBuilder("<ul>\n");
            List<string> InstalledThemes = new InstalledThemes().InstalledThemesList();

            foreach (String ThemeName in InstalledThemes)
                sb.Append("<li><a href='" + new Urls().Home + "?ThemeName=" + ThemeName + "'>" + ThemeName + "</a>\n");

            sb.Append("</ul>\n");
            return sb.ToString();
        }

    }
}
